package com.juyu.miliao.common.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;
import java.util.List;



public class Subject implements UserDetails{
	private static final long serialVersionUID = -9156728081092451651L;
	private long id;
	private int sex;
	private String username;
	private String password;
	private String nickName;
	private String icon;
	private String channel;
	private Boolean firstRegister;
	private String appPackageId;
	private boolean isAudit;
	private int isVip;
	private int isHost;
	//1:老用户新手引导不送寻币样式
	//2:新用户且绑定手机号送500寻币样式
	//3:新用户且未绑定手机号提醒送寻币样式
	private int isNewUserBindingPhone;

	private final List<GrantedAuthority> authorities;

	public Subject(long id, String password, List<GrantedAuthority> authorities){
		this.id = id;
		this.username = String.valueOf(id);
		this.password = password;
		this.authorities = authorities;
	}

	public Subject(long id, String username, String password, List<GrantedAuthority> authorities) {
		super();
		this.id = id;
		this.username = username;
		this.password = password;
		this.authorities = authorities;
	}

	public Subject(long id, String password){
		this.id = id;
		this.username = String.valueOf(id);
		this.password = password;
		this.authorities = Collections.emptyList();
	}
	
	public Subject(long id){
		this.id = id;
		this.username = String.valueOf(id);
		this.password = "";
		this.authorities = Collections.emptyList();
	}

	public Subject(long id,int sex, String nickName, String icon, String channel, Boolean firstRegister,String appPackageId,boolean isAudit) {
		this.id = id;
		this.sex = sex;
		this.nickName = nickName;
		this.icon = icon;
		this.channel = channel;
		this.username = String.valueOf(id);
		this.password = "";
		this.authorities = Collections.emptyList();
		if (firstRegister == null) {
			firstRegister = false;
		}
		this.firstRegister = firstRegister;
		this.appPackageId=appPackageId;
		this.isAudit = isAudit;

	}
//	public Subject(long id,int sex, String nickName, String icon,
//				int isVip,int isHost,String channel,
//				   Boolean firstRegister,String appPackageId,boolean isAudit) {
//		this.id = id;
//		this.sex = sex;
//		this.nickName = nickName;
//		this.icon = icon;
//		this.channel = channel;
//		this.username = String.valueOf(id);
//		this.password = "";
//		this.authorities = Collections.emptyList();
//		if (firstRegister == null) {
//			firstRegister = false;
//		}
//		this.firstRegister = firstRegister;
//		this.appPackageId=appPackageId;
//		this.isAudit = isAudit;
//		this.isVip = isVip;
//		this.isHost = isHost;
//
//	}
	public Subject(long id,int sex, String nickName, String icon,
				   int isVip,int isHost,String channel,
				   Boolean firstRegister,String appPackageId,boolean isAudit,String username,int isNewUserBindingPhone) {
		this.id = id;
		this.sex = sex;
		this.nickName = nickName;
		this.icon = icon;
		this.channel = channel;
		this.username = String.valueOf(id);
		this.password = "";
		this.authorities = Collections.emptyList();
		if (firstRegister == null) {
			firstRegister = false;
		}
		this.firstRegister = firstRegister;
		this.appPackageId=appPackageId;
		this.isAudit = isAudit;
		this.isVip = isVip;
		this.isHost = isHost;
		if(username==null){
			this.username="";
		}else {
			this.username = username;
		}
		this.isNewUserBindingPhone = isNewUserBindingPhone;
	}

	public int getIsNewUserBindingPhone() {
		return isNewUserBindingPhone;
	}

	public int getIsVip() {
		return isVip;
	}

	public void setIsVip(int isVip) {
		this.isVip = isVip;
	}

	public int getIsHost() {
		return isHost;
	}

	public void setIsHost(int isHost) {
		this.isHost = isHost;
	}

	public boolean getIsAudit() {
		return isAudit;
	}

	public void setIsAudit(boolean isAudit) {
		isAudit = isAudit;
	}

	public int getSex() {
		return sex;
	}

	public void setSex(int sex) {
		this.sex = sex;
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return authorities;
	}

	public void addAuthoritie(GrantedAuthority authority){
		authorities.add(authority);
	}
	
	@Override
	@JsonIgnore
	public String getPassword() {
		return password;
	}

	@Override
	public String getUsername() {
		return username;
	}

	@Override
	@JsonIgnore
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	@JsonIgnore
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	@JsonIgnore
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	@JsonIgnore
	public boolean isEnabled() {
		return true;
	}

	public long getId() {
		return id;
	}

	public String getNickName() {
		return nickName;
	}

	public String getIcon() {
		return icon;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getChannel() {
		return channel;
	}

	public void setChannel(String channel) {
		this.channel = channel;
	}

	public Boolean getFirstRegister() {
		return firstRegister;
	}

	public String getAppPackageId() {
		return appPackageId;
	}
}
